<template>
  <div class="page-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-background">
        <div class="bg-pattern"></div>
        <div class="bg-gradient"></div>
      </div>
      
      <div class="page-title">
        <div class="title-icon">
          <div class="icon-container" style="width: 36px; height: 36px; background: linear-gradient(135deg, #9c27b0 0%, #ba68c8 100%); border-radius: 8px; color: white; box-shadow: 0 2px 8px rgba(156, 39, 176, 0.2);">
            <el-icon size="20"><Document /></el-icon>
            <div class="icon-glow"></div>
          </div>
        </div>
        <div class="title-content">
          <div class="title-main">
            <h1>日志统计</h1>
            <div class="title-badge">
              <el-icon><Star /></el-icon>
              <span>LOGS</span>
            </div>
          </div>
          <p class="page-description">
            <el-icon><DataAnalysis /></el-icon>
            统一的日志分析和统计平台
          </p>
          <div class="title-meta">
            <div class="meta-item">
              <el-icon><Connection /></el-icon>
              <span>API日志</span>
            </div>
            <div class="meta-item">
              <el-icon><FolderOpened /></el-icon>
              <span>存储审计</span>
            </div>
            <div class="meta-item">
              <el-icon><TrendCharts /></el-icon>
              <span>趋势分析</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 日志类型卡片网格 -->
    <div class="cards-grid">
      <el-card 
        v-for="log in logTypes" 
        :key="log.name"
        class="feature-card"
        shadow="hover"
      >
        <div class="status-badge">
          <el-tag :type="log.status === 'active' ? 'success' : 'info'" size="small">
            {{ log.status === 'active' ? '可用' : '开发中' }}
          </el-tag>
        </div>
        <div class="card-content-layout">
          <div class="card-content-icon" :style="{ background: `linear-gradient(135deg, ${log.color}15 0%, ${log.color}08 100%)` }">
            <el-icon :size="32" :color="log.color">
              <component :is="log.icon" />
            </el-icon>
          </div>
          <div class="card-content-body">
            <h3 class="card-content-title">{{ log.title }}</h3>
            <p class="card-content-description">{{ log.description }}</p>
            <div class="features-list">
              <span 
                v-for="feature in log.features" 
                :key="feature"
                class="feature-tag"
              >
                <el-icon><Check /></el-icon>
                {{ feature }}
              </span>
            </div>
            
            <!-- 操作按钮 -->
            <div class="card-actions">
              <el-button 
                type="primary" 
                :icon="DataAnalysis"
                @click="navigateToAnalysis(log)"
                :disabled="log.status !== 'active'"
              >
                分析页面
              </el-button>
              <el-button 
                type="default" 
                :icon="Document"
                @click="navigateToList(log)"
                :disabled="log.status !== 'active'"
              >
                列表页面
              </el-button>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, markRaw } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  Connection, FolderOpened, Document, 
  Star, DataAnalysis, TrendCharts, Check,
  WarningFilled
} from '@element-plus/icons-vue'
import { componentLogger } from '@/utils/logger'

const router = useRouter()

// 日志类型列表
const logTypes = ref([
  {
    name: 'spring-api',
    title: 'Spring API日志',
    description: 'API请求日志分析，包含服务健康度、接口调用统计、错误分析等',
    icon: markRaw(Connection),
    color: '#409EFF',
    status: 'active',
    features: ['服务监控', '接口统计', '错误分析', '慢接口追踪'],
    analysisPath: '/logs/api',
    listPath: '/logs/api/list'
  },
  {
    name: 'minio-audit',
    title: 'Minio审计日志',
    description: '对象存储审计日志，包含请求统计、桶分析、流量趋势等',
    icon: markRaw(FolderOpened),
    color: '#67C23A',
    status: 'active',
    features: ['请求统计', '桶分析', '流量监控', 'API分布'],
    analysisPath: '/logs/minio',
    listPath: '/logs/minio/list'
  },
  {
    name: 'flink-job',
    title: 'Flink Job日志',
    description: '按类维度分析 Flink 日志，包含类健康度、错误监控、趋势分析等',
    icon: markRaw(Connection),
    color: '#E6A23C',
    status: 'active',
    features: ['类健康度', '错误监控', '趋势分析', '日志查询'],
    analysisPath: '/logs/flink-job',
    listPath: '/logs/flink-job/list'
  },
  {
    name: 'starrocks-error',
    title: 'StarRocks 错误日志',
    description: '聚焦 StarRocks 运行日志，支持集群维度分析',
    icon: markRaw(WarningFilled),
    color: '#F56C6C',
    status: 'active',
    features: ['错误指纹', '集群分布', '趋势分析', '日志查询'],
    analysisPath: '/logs/starrocks-error',
    listPath: '/logs/starrocks-error/list'
  },
  {
    name: 'starrocks-query',
    title: 'StarRocks 查询日志',
    description: 'SQL 审计和慢查询分析，支持用户、数据库、执行时间等多维度筛选',
    icon: markRaw(DataAnalysis),
    color: '#409EFF',
    status: 'active',
    features: ['SQL审计', '慢查询分析', '执行统计', '用户行为'],
    analysisPath: '/logs/starrocks-query',
    listPath: '/logs/starrocks-query/list'
  }
])

// 导航到分析页面
const navigateToAnalysis = (log) => {
  if (log.status !== 'active') {
    ElMessage.warning('该功能正在开发中，敬请期待')
    return
  }
  
  componentLogger.info('导航到日志分析页面', { log: log.name, path: log.analysisPath })
  router.push(log.analysisPath)
}

// 导航到列表页面
const navigateToList = (log) => {
  if (log.status !== 'active') {
    ElMessage.warning('该功能正在开发中，敬请期待')
    return
  }
  
  componentLogger.info('导航到日志列表页面', { log: log.name, path: log.listPath })
  router.push(log.listPath)
}
</script>

<style scoped>
/* 使用全局设计系统样式 */
/* 页面特定样式可以在这里添加 */
.page-container {
  background: transparent !important;
  padding: 0;
}

/* 页面标题样式 - 与 Jobs 页面保持一致 */
.page-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 20px 24px;
  border-radius: 12px;
  overflow: hidden;
  color: #303133;
  min-height: 120px;
  border: 1px solid #e4e7ed;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.05;
  pointer-events: none;
}

.title-icon {
  position: relative;
}

.page-header .title-icon .icon-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  height: 36px !important;
  border-radius: 8px !important;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(156, 39, 176, 0.2) !important;
}

.page-header .title-icon .icon-container:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(156, 39, 176, 0.3) !important;
}

.page-header .title-icon .icon-glow {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  background: linear-gradient(45deg, rgba(156, 39, 176, 0.2), rgba(186, 104, 200, 0.3));
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.page-header .title-icon .icon-container:hover .icon-glow {
  opacity: 1;
}

.title-content {
  flex: 1;
}

.title-main {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.title-main h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  letter-spacing: -0.3px;
}

.title-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #9c27b0 0%, #ba68c8 100%);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(156, 39, 176, 0.25);
}

.page-description {
  margin: 0 0 12px 0;
  color: #606266;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-description .el-icon {
  font-size: 16px;
  color: #909399;
}

.title-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #909399;
  font-size: 12px;
  font-weight: 500;
}
</style>
